//
//  DrawLineView.m
//  SoulBall
//
//  Created by Vic on 2019/12/6.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "DrawLineView.h"

@interface DrawLineView ()

@property (nonatomic, strong) CAShapeLayer * slayer;

@end

@implementation DrawLineView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.backgroundColor = [UIColor clearColor].CGColor;
        _lines = [NSMutableArray arrayWithCapacity:0];
    }
    return self;
}
/**
 *  画线
 */
- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    if (!self.lines.count) return;
    for (CAShapeLayer *shapeLayer in self.lines) {
        [self.layer addSublayer:shapeLayer];
    }
}
/**
 *  清屏
 */
- (void)clearScreen {
    if (!self.lines.count) return;
    [self.lines makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
    [[self mutableArrayValueForKey:@"lines"] removeAllObjects];
}

@end
